# Maintainer: Anatol Pomozov <anatol pomozov at gmail> 
# Contributor: Daniel YC Lin <dlin.tw at gmail>
# Contributor: Konstantin Plotnikov <kostyapl at gmail dot com>

pkgname=fossil
pkgver=2.21
_tag=f9aa474081f0618c76f4c2f4d6f0277a3fd480aa185d7da0b8b61b00fad1aa78
pkgrel=1
pkgdesc='Simple, high-reliability, distributed software configuration management'
arch=(loong64 x86_64)
license=(BSD)
url='https://www.fossil-scm.org'
depends=(openssl zlib sqlite)
makedepends=(tcl)
optdepends=(tcl)
backup=(etc/xinetd.d/fossil)
source=(
  fossil.socket
  fossil.service
  fossil-xinetd
  https://fossil-scm.org/home/tarball/$_tag/fossil-src-$pkgver.tar.gz
)
sha256sums=('f885e17998dc1eece1688a75e516663462fe72a7f4f132def4132055777c7ff8'
            'c4973079facf209d3757db81df08f8d0843ede242f2a0c12281720da65e3b166'
            '2f9a141fadfb7cb5225f0d65a308949bbc592bff9d567b5c472edb413c81f5aa'
            '195faf0b20c101834a809979d0a9cdf04a0dcbae1fdabae792c9db900b73bda0')

build() {
  cd fossil-src-$pkgver
  ./configure --prefix=/usr --json --disable-internal-sqlite --with-tcl=/usr --with-tcl-private-stubs=1
  # headers and translate targets are problematic with parallel jobs
  #make -j1 bld bld/headers
  make
}

package() {
  install -Dm644 fossil-xinetd "$pkgdir"/etc/xinetd.d/fossil
  install -Dm644 fossil.socket "$pkgdir"/usr/lib/systemd/system/fossil.socket
  install -Dm644 fossil.service "$pkgdir"/usr/lib/systemd/system/fossil@.service

  cd fossil-src-$pkgver
  install -Dm755 fossil "$pkgdir"/usr/bin/fossil
  install -Dm644 tools/fossil-autocomplete.bash "$pkgdir"/usr/share/bash-completion/completions/fossil
  install -Dm644 tools/fossil-autocomplete.zsh "$pkgdir"/usr/share/zsh/site-functions/_fossil
  install -Dm644 COPYRIGHT-BSD2.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
